package com.aconcagua.context {
  import com.aconcagua.factory.MXMLBeanFactory;
  
  import flash.events.Event;
  
  import mx.core.Application;
  import mx.events.FlexEvent;

  [Event(name="contextComplete")]
  public class ApplicationContext extends MXMLBeanFactory {
    public static const CONTEXT_COMPLETE: String = "contextComplete";

    private var _application: Application;

    [Bindable]
    public function set application(app: Application): void {
      _application = app;
      _application.addEventListener(FlexEvent.APPLICATION_COMPLETE, initBeanFactory);
    }      
  
    public function get application(): Application {
      return _application;
    }
    
    private function initBeanFactory(event: Event): void {
      this.init();
      this.dispatchEvent(new Event(CONTEXT_COMPLETE, true));
    }
  }
}